//-----------------------------------------------------------------------
// <copyright file="LogOnPresenter.cs" company="Simnova LLC">
//     Copyright (c) Simnova LLC. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Simnova.Collaborate.Presenter
{
    using System;
    using System.Collections.Generic;
    using System.Text;

    public class LogOnPresenter
    {
        private readonly View.ILogOn logOnView;

        public LogOnPresenter(View.ILogOn logOnView)
        {
            this.logOnView = logOnView;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns>UserID</returns>
        public int LogOn()
        {
            AppServer.CollaborateServiceClient collaborateClient = new AppServer.CollaborateServiceClient();

            AppServer.User user = collaborateClient.GetUser(this.logOnView.EmailAddress, this.logOnView.Password);
            collaborateClient.Close();
            if (user == null)
            {
                throw new LogOnException("Login Failed");
            }
            else
            {
                return user.UserId;
            }
        }

        public class LogOnException : Exception
        {
            public LogOnException(string message)
                : base(message)
            {
            }
        }
    }
}
